import store from '../store';
const hasPermission = {
    install (Vue) {
          Vue.directive('has', {
            inserted: (el, binding, vnode)=>{
                  filterGlobalPermission(el, binding, vnode);

            }
          });
    }
};

/**
 * 判断是否有权限,有返回true, 没有返回false
 */
export function hasPermissionFunc(permissionStr){
  let authList = store.getters.auth;
  for (let auth of authList) {
    if(permissionStr === auth.action){
      return true;
    }
  }
  return false;
}

/**
 * 全局权限控制
 */
export function filterGlobalPermission(el, binding) {
  if(hasPermissionFunc(binding.value)){
    return;
  }
  el.parentNode.removeChild(el);

}

export default hasPermission;
